﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace XLB.ExtensionMethod
{
    /// <summary>
    /// 字符串处理类
    /// </summary>
    public class StringHelper
    {
        /// <summary>
        /// 统计指定字符串出现次数
        /// </summary>
        /// <param name="MatchString">被用来匹配的字符串</param>
        /// <param name="IncomingString">传入的字符串</param>
        /// <returns>IncomingString字符串里MatchString中各字符出现的次数</returns>
        public static Dictionary<string, int> StatisticsStringAppearFrequency(string MatchString, string IncomingString)
        {
            Dictionary<string, int> dic = new Dictionary<string, int>();
            foreach (var item in IncomingString)
            {
                if (MatchString.Contains(item)) //表示在指定字符内
                {
                    if (!dic.ContainsKey(item.ToString()))
                    {
                        dic.Add(item.ToString(), 1);
                    }
                    else
                    {
                        dic[item.ToString()] += 1;
                    }
                }
            }

            return dic;

    }
    }
}
